﻿using System;
using System.Text;

namespace ZYCommon
{
    

    public class Format_InList : StringDataFormatItem
    {
        public override bool CanEditSetting()
        {
            return true;
        }

        protected string[] GetItems(string strValue)
        {
            return strValue.Split(",;，；、".ToCharArray());
        }

        public override bool Test(string strValue)
        {
            if ((base.strSetting != null) && (strValue != null))
            {
                strValue = strValue.Trim();
                string[] items = this.GetItems(base.strSetting);
                if (items.Length > 0)
                {
                    foreach (string str in items)
                    {
                        if (strValue.Equals(str.Trim()))
                        {
                            return true;
                        }
                    }
                    return false;
                }
            }
            return true;
        }

        public override string DisplayName
        {
            get
            {
                return ("必须在[" + base.strSetting + "]中选一个");
            }
        }

        public override string Name
        {
            get
            {
                return "inlist";
            }
        }

        public override string SettingValue
        {
            get
            {
                return base.strSetting;
            }
            set
            {
                if (value == null)
                {
                    base.strSetting = "";
                }
                else
                {
                    string[] items = this.GetItems(value);
                    StringBuilder builder = new StringBuilder();
                    foreach (string str in items)
                    {
                        if (str.Trim().Length > 0)
                        {
                            if (builder.Length > 0)
                            {
                                builder.Append(",");
                            }
                            builder.Append(str.Trim());
                        }
                    }
                    base.strSetting = builder.ToString();
                }
            }
        }
    }
}

